package com.iotproject.studyservice.controller;

import com.iotproject.commonutils.R;
import com.iotproject.studyservice.entity.StudyGrade;
import com.iotproject.studyservice.entity.StudyWord;
import com.iotproject.studyservice.service.StudyGradeService;
import com.iotproject.studyservice.service.StudyWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/studyservice/unremember-word")
public class UnRememberController {

    @Autowired
    StudyWordService studyWordService;

    @Autowired
    StudyGradeService studyGradeService;

    //点击不认识单词
    @GetMapping("unrememberWord/{wordId}")
    public R unrememberWord(@PathVariable("wordId") String wordId, HttpServletRequest httpServletRequest) {
        //展示单词意思
        StudyWord studyWord = studyWordService.getById(wordId);
        //查询等级名称
        String grade = studyWord.getGrade();
        StudyGrade studyGrade = studyGradeService.getById(grade);
        String gradeName = studyGrade.getName();
        //展示进度条信息
        Map<String, Double> progress = studyWordService.progress(grade, httpServletRequest);
        Double rememberPercent = progress.get("rememberPercent");
        Double forgetPercent = progress.get("forgetPercent");

        //加入生词本

        return R.ok().data("gradeName", gradeName).data("word", studyWord).data("rememberPercent", rememberPercent).data("forgetPercent", forgetPercent);
    }

}
